package com.springboot.demo.threadpool;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

public class ThreadPoolTest {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        ThreadPoolExecutor pool = (ThreadPoolExecutor)Executors.newFixedThreadPool(1);
        ExecutorService executorService = Executors.newCachedThreadPool();
        Callable cun = () -> {
            System.out.println(1);
            TimeUnit.MILLISECONDS.sleep(1000);
            return "static";
        };


        List<Callable<String>> arr = new ArrayList<>();
        arr.add(cun);
        arr.add(cun);
        arr.add(cun);
        arr.add(cun);
        String futures = pool.invokeAny(arr);
        int poolSize = pool.getPoolSize();
        int size = pool.getQueue().size();
        System.out.println(futures);
        System.out.println("queue size = "+size + " , pool size = "+poolSize);
        TimeUnit.MILLISECONDS.sleep(1000);
        System.out.println(pool.getQueue().size());

    }
}
